<template>
	<view class="safe-area-inset-bottom">
		<view class="swip_header">
			<view class="slot-box">
				<view style="width: 100%;">
					<uni-search-bar v-model="queryParams.regMobile" type="text" @confirm="handleQuery"
						@input="handleQuery" placeholder="请输入客户名称/管理员姓名/账号" />
				</view>
			</view>
		</view>

		<!-- 分享记录 -->
		<view class="listSearchTop" v-if="shareRegList != ''">
			<uni-card :is-shadow="false" v-for="(item,index) in shareRegList" :key="index" class="card-list">
					<p class="grid-integral">企业客户名称：</p>
					<p class="grid-integral" style="color:rgb(255, 189, 33)">管理员姓名账号：{{ item.amount }}碳能量</p>
					<p class="grid-integral">管理员身份：{{ item.number }}</p>
					<p class="grid-integral">企业认证状态：{{ item.number }}</p>
					<p class="grid-integral">注册渠道：{{ item.number }}</p>
					<p class="grid-integral">碳能量分享奖：<span style="color: #67c23a;">+{{ item.addIntegral }}</span></p>
					<p class="grid-integral">分享人：{{ item.number }}</p>
					<p class="grid-integral" style="color:#999999">注册时间：{{item.createTime}}</p>
					<p class="grid-integral" style="color:#999999" v-if="!!item.contractEndTime">认证时间：{{item.contractEndTime}}</p>
					<p class="grid-integral" style="color:#999999" v-else>认证时间：认证时间暂无</p>
					<view slot="actions" class="card-actions">
						<view class="card-actions-item" @click="handleQuick(item)">
						<uni-icons type="paperplane" size="18" color="#00a660"></uni-icons>
						<text class="card-actions-item-text themeColor">催一下</text>
					</view>
						<view class="card-actions-item" @click="handleDelete(item,index)">
						<uni-icons type="trash" size="18" color="#00a660"></uni-icons>
						<text class="card-actions-item-text themeColor">删除</text>
					</view>
					</view>		    
				</uni-card>
			<!-- 加载更多 -->
			<uni-load-more color="#00a660" :status="loadStatus"/>
		</view>

		<!-- 暂无数据 -->
		<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
	</view>
</template>

<script>
	import luanqingEmpty from '@/components/luanqing-empty/luanqing-empty';
	import {listShareReg, delShareReg, } from "@/api/ec/person/shareReg/shareReg";
	export default {
		components: {luanqingEmpty},
		data() {
			return {
				total:0 ,//总条数
				loadStatus:'loading', //是否加载中 //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				// 账户余额明细表格数据
				shareRegList: [],
				// 查询参数
				queryParams: {
				  pageNum: 1,
				  pageSize: 10,
				  nickId: null,
				  staffId: null,
				  regMobile: null,
				  addIntegral: null,
				},      
			}
		},
		onLoad() {
			this.getList();
		},
		/** 上拉刷新回调 */
		onReachBottom() {
		  if (this.loadStatus != 'noMore' && this.total > this.shareRegList.length) {
		    this.loadStatus = 'loading';
		    // 延迟500毫秒显示loading效果
		    setTimeout(() => {
		      // 执行查询的方法
		      this.getList(false);
		    }, 500)
		  } else {
		    // 停止加载
		    this.loadStatus = 'noMore'
		  }
		},
		methods: {
			/** 搜索按钮操作 */
			handleQuery() {
				this.getList(true);
			},
			/** 查询列表 */
			getList(reload) {
			  if (reload) {
			    this.queryParams.pageNum = 1;
			    this.loadStatus = 'more'
          this.$modal.loading();
			  }
			  listShareReg(this.queryParams).then(response => {
			    if (reload) {
			      uni.hideLoading()
			    }
			    this.total = response.total;
			    if (response.total > 0) {
			      const dataRows = response.rows;
			      this.shareRegList = reload ? dataRows : this.shareRegList.concat(dataRows);
			    } else {
			      this.shareRegList = [];
			    }
			    // 判断数据是否加载完全 
			    if (response.total <= this.shareRegList.length) {
			      this.loadStatus = 'noMore'
			    }
			    // 页数+1
			    this.queryParams.pageNum++
			  }).catch(() => {
			    if (reload) {
			      uni.hideLoading()
			    }
			  });
			},
			/** 删除 */
			handleDelete(row, index) {
			 var _this = this
			 uni.showModal({
			 	title: '系统提示',
			 	content: '是否删除该员工的分享记录？',
			 	confirmColor: '#00a660',
			 	success: function(res) {
			 		if (res.confirm) {
			 			delShareReg(row.id)
			 			_this.$modal.msgSuccess("删除成功");
			 			_this.shareRegList.splice(index, 1)
			 		} else {}
			 	}
			 })		
			},
			handleQuick(row){
				this.$modal.msgSuccess("催一下成功");
			},
		}
	}
</script>

<style scoped lang="scss">
	.card-actions {
	  display: flex;
	  flex-direction: row;
	  justify-content: space-around;
	  align-items: center;
	  height: 45px;
	  border-top: 1px #eee solid;
	}
	
	.card-actions-item {
	  display: flex;
	  flex-direction: row;
	  align-items: center;
	  font-size: 26rpx;
	}
	page {
		background: $uni-bg-color-grey;
	}
</style>
